#include "Semaphore.h"

using namespace std;

#ifdef CONCURENT

#include "BufferManager.h"

void SEM_CREATE(SEMAPHORE& sem)
{
    pthread_rwlock_init(&sem, NULL);
}

void SEM_READLOCK(SEMAPHORE& sem)
{
    pthread_rwlock_rdlock(&sem);
}

void SEM_WRITELOCK(SEMAPHORE& sem)
{
    pthread_rwlock_wrlock(&sem);
}

int SEM_TRYWRITELOCK(SEMAPHORE& sem)
{
    return pthread_rwlock_trywrlock(&sem);
}

void SEM_UNLOCK(SEMAPHORE& sem)
{
    pthread_rwlock_unlock(&sem);
}

void SEM_DESTROY(SEMAPHORE& sem)
{
    pthread_rwlock_destroy(&sem);
}
#else
void SEM_CREATE(SEMAPHORE& sem){}
void SEM_READLOCK(SEMAPHORE& sem){}
void SEM_WRITELOCK(SEMAPHORE& sem){}
int SEM_TRYWRITELOCK(SEMAPHORE& sem)
{
    return 0;
}
void SEM_UNLOCK(SEMAPHORE& sem){}
void SEM_DESTROY(SEMAPHORE& sem){}
#endif
